import {CHANGE_INPUT , ADD_ITEM , DEL_ITEM , GET_LIST} from './actionTypes'
const defalutState = {
    inputValue:'write Something',
    list:[
        '早晨开会',
    '下午开会',
    '中午开会'
    ]
}
export default (state = defalutState , action )=>{
    //reaucer 里只能接受state，不能改变state
    // console.log(state , action)

    if(action.type === CHANGE_INPUT){
        let newState = JSON.parse(JSON.stringify(state))
        newState.inputValue = action.value
        return newState
    }
    if(action.type === ADD_ITEM){
        let newState = JSON.parse(JSON.stringify(state))
        newState.list.push(newState.inputValue)
        newState.inputValue = ''
        return newState
    }
    if(action.type === DEL_ITEM){
        let newState = JSON.parse(JSON.stringify(state))
        newState.list.splice(action.index,1)
        return newState
    }

    if(action.type == GET_LIST){
        let newState = JSON.parse(JSON.stringify(state))
        newState.list = action.data
        return newState
    }

    return state;
}